package me.panpf.sketch.adapter.pager;

import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.PageSliderProvider;

import java.util.List;

public class ViewArrayPagerAdapter extends PageSliderProvider {
    private List<Component> mList;
    private String[] mTabTitles;

    public ViewArrayPagerAdapter(List<Component> list) {
        this.mList = list;
    }

    public ViewArrayPagerAdapter(List<Component> list, String[] tabTitles) {
        this.mList = list;
        this.mTabTitles = tabTitles;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        componentContainer.addComponent(mList.get(i));
        return mList.get(i);
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent(mList.get(i));
    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return component == o;
    }

    @Override
    public String getPageTitle(int position) {
        if (mTabTitles != null) {
            return mTabTitles[position];
        }
        return super.getPageTitle(position);
    }

}
